package com.heaven.back.utils.Inits;

import com.heaven.back.pojo.Game;
import com.heaven.back.pojo.Item;
import com.heaven.back.pojo.Room;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static com.heaven.back.utils.RandomNumberGenerator.getRandomNumberInRange;


/**
 * The type Item init.
 */
@Slf4j
@Component
public class ItemInit {
    /**
     * The Item sets.
     */
    List<Item> itemSets = new ArrayList<>();

    /**
     * Initial items.
     */
    public void initialItems() {
        /*item_sets.put("木棍",new Item("木棍","随处可见的木棍",0.25));
        item_sets.put("木板",new Item("木板","基本建筑材料之一",0.5));
        item_sets.put("原木",new Item("原木","要致富，先撸树！",2));
        item_sets.put("沙子",new Item("沙子","为什么沙子能捡起来？",0.5));
        item_sets.put("仙人掌",new Item("仙人掌","小心点，别刺伤了自己！",1));
        Item magicCookie = new Item("魔法饼干","据说吃了能变大力！",0.5);
        magicCookie.setEatEffect(1,1);
        item_sets.put("魔法饼干",magicCookie);
        Item db = new Item("大便","很臭......",1);
        db.setEatEffect(2,0);
        item_sets.put("大便",db);*/
        //actionMapper.item();
        itemSets.add(new Item("木棍", "随处可见的木棍", 0.25));
        itemSets.add(new Item("木板", "基本建筑材料之一", 0.5));
        itemSets.add(new Item("沙子", "为什么沙子能捡起来？", 0.5));
        itemSets.add(new Item("仙人掌", "小心点，别刺伤了自己！", 1));
        itemSets.add(new Item("魔法饼干", "据说吃了能变大力！", 0.5, 1, 1));
        itemSets.add(new Item("大便", "很臭......", 1, 2, 0));
        itemSets.add(new Item("金条", "据说很值钱！", 5));
        itemSets.add(new Item("书与笔", "欢迎来到我的世界！", 1));
        itemSets.add(new Item("大石头", "非常重的石头......", 1));
        itemSets.add(new Item("钻石", "钻石是黑暗中蓝色的光芒", 8));
        itemSets.add(new Item("金胡萝卜", "金胡萝卜是—种高价值的食物类物品和酿造材料！", 2, 3, 2));
        itemSets.add(new Item("鸡蛋", "鸡蛋是—种可以由鸡产下的物品。", 1, 4, -1));
        itemSets.add(new Item("黑曜石", "它反光、易碎、边缘透明，且颜色深、很光滑", 4));
        itemSets.add(new Item("TNT", "来啊，把它点着！", 0.5));
    }

    /**
     * 创建所有房间物品对象并给予名字、描述与重量值.
     *
     * @param game the game
     */
    public void itemInit(Game game) {
        //初始化物品种类
        initialItems();
        //随机分配物品
        int length = itemSets.size() - 1;
        HashMap<String, Room> game_map = game.getGameMap();
        int min = 10; // 指定范围的最小值
        int max = 11; // 指定范围的最大值
        int randomNumber = getRandomNumberInRange(min, max);

        for (int i = 0; i < randomNumber; i++) {
            game_map.get("森林中心").addItem(itemSets.get(getRandomNumberInRange(0, length)));
            game_map.get("森林东部").addItem(itemSets.get(getRandomNumberInRange(0, length)));
            game_map.get("森林北部").addItem(itemSets.get(getRandomNumberInRange(0, length)));
            game_map.get("沙漠北部").addItem(itemSets.get(getRandomNumberInRange(0, length)));
            game_map.get("沙漠神殿入口").addItem(itemSets.get(getRandomNumberInRange(0, length)));
            game_map.get("森林池塘").addItem(itemSets.get(getRandomNumberInRange(0, length)));
            game_map.get("小沼泽").addItem(itemSets.get(getRandomNumberInRange(0, length)));
            game_map.get("村庄入口").addItem(itemSets.get(getRandomNumberInRange(0, length)));
        }
    }
}
